package com.hankol.winecellar.adapter

import android.widget.ImageView
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.extension.load
import com.baselibrary.utils.CommonUtil
import com.baselibrary.utils.GlideUtils
import com.baselibrary.utils.NumberUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.winecellar.R
import com.hankol.winecellar.bean.WineryCommonToolBean

//经营者中心--酒窖管理 列表
class WineryCenterFunctionServerAdapter : BaseQuickAdapter<WineryCommonToolBean, BaseViewHolder>(R.layout.item_winery_manager_function) {
    //  0已发布   1已冻结  2  待发布  3：审核中
    private var wineryState: Int = -1


    fun setWineryState(wineryState: Int) {
        this.wineryState = wineryState
    }

    //类型 0未发布 1已发布" 2 首次发布被拒
    private var type: Int = -1
    fun setWineryType(type: Int) {
        this.type = type
    }

    override fun convert(helper: BaseViewHolder, item: WineryCommonToolBean) {
        GlideUtils.loadImg_101(
            mContext, item.icon.checkValue(), helper.getView<ImageView>(R.id.img_cover_winery)
        )
        helper.setText(R.id.tv_name_winery, item.name.checkValue())
        //新零售优化，暂时隐藏
        /*  helper.setGone(R.id.img_status_winery, (helper.adapterPosition == 0 && wineryState != -1))
          if (helper.adapterPosition == 0) {
              var stateRes = 0
              when (wineryState) {
                  0 -> {//已发布
                      stateRes = if (type == 0) R.drawable.ic_online_wait else R.drawable.ic_online_ok
                  }
                  1 -> {
                      //已冻结
                      stateRes = R.drawable.ic_online_freeze
                  }
                  2 -> {
                      //待发布
                      stateRes = R.drawable.ic_online_wait
                  }
                  3 -> {
                      stateRes = if (type == 0) R.drawable.ic_online_wait else R.drawable.ic_online_ok
                  }
              }
              helper.getView<ImageView>(R.id.img_status_winery).load(mContext, stateRes)
          }*/

        if (item.tips.checkNotNull()) {
            if (NumberUtils.isNumeric(item.tips)) {
                helper.setGone(R.id.tv_cnt, true)
                helper.setGone(R.id.tv_str_tip, false)
                CommonUtil.formatNum99(helper.getView(R.id.tv_cnt), item.tips.checkValue().toInt())
            } else {
                //文字角标
                helper.setGone(R.id.tv_cnt, false)
                helper.setGone(R.id.tv_str_tip, true)
                helper.setText(R.id.tv_str_tip, item.tips.checkValue());
            }
        } else {
            helper.setGone(R.id.tv_cnt, false)
            helper.setGone(R.id.tv_str_tip, false)
        }
    }

}